package com.ys.bean.support;

import com.ys.enumeration.BeanScope;

import java.io.Serializable;

/**
 * <p>@description:bean定义 </p>
 *
 * @projectName: Spring-Mini
 * @className: BeanDefinition
 * @author: yangshuang
 * @date: 2016/12/11 17:24
 */
public class BeanDefinition implements Serializable {
    private static final long serialVersionUID = 6386610169347037342L;
    private Class<?> beanClass;//bean实例的类
    private BeanScope scope;//类型:单利,原型,会话级别,线程私有
    private String beanName;//bean的名字
    private Object beanInstance;//bean实例
    private PropertyValues propertyValues=new PropertyValues();//bean的属性值

    public BeanDefinition(BeanScope scope, String beanName, Class<?> beanClass) {
        this.beanClass = beanClass;
        this.scope = scope;
        this.beanName = beanName;
    }

    public BeanDefinition(BeanScope scope, String beanName, Object beanInstance) {
        this.scope = scope;
        this.beanName = beanName;
        this.beanInstance = beanInstance;
        this.beanClass = beanInstance.getClass();
    }

    public Class<?> getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    public BeanScope getScope() {
        return scope;
    }

    public void setScope(BeanScope scope) {
        this.scope = scope;
    }

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }


    public Object getBeanInstance() {
        return beanInstance;
    }

    public void setBeanInstance(Object beanInstance) {
        this.beanInstance = beanInstance;
    }

    /**
     * <p>函数功能说明:是否匹配当前类型的bean</p>
     * <p>Bieber  2014-5-11</p>
     * <p>修改者名字 修改日期</p>
     * <p>修改内容</a>
     *
     * @return boolean
     */
    public boolean isMatchType(Class<?> type) {
        if (type == null) {
            return false;
        }
        return type.isAssignableFrom(beanClass);
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }
}
